import { delCache } from "#server/utils/context"; import { z } from "zod"; import { updateTool, getToolById } from "../../service/tool"; const updateSchema = z.object({ name: z.string().min(1).max(50).optional(), slug: z.string().min(1).max(50).optional(), icon: z.string().max(100).nullable().optional(), sortOrder: z.number().int().optional(), }); export default defineWrappedResponseHandler(async (event) => { const id = getRouterParam(event, "id"); if (!id) return R.throwError(400, "Missing id", null); const body = await readBody(event); const parsed = updateSchema.safeParse(body); if (!parsed.success) { return R.throwError(422, "Validation failed", parsed.error.issues); } const existing = await getToolById(id); if (!existing) return R.throwError(404, "Tool not found", null); const updated = await updateTool(id, parsed.data); await delCache(`tool:${id}`); await delCache("tools:list"); return R.success(updated); });